<?php
include("../contents.php");
include("../security.php");
include("../settings.php");
include("../database.php");
if (Contents::presence_rights($_GET["pres"])) {
	echo "<"."?xml version=\"1.0\"?".">";
	
	if(!empty($_POST)) {
		mysql_query("UPDATE ". $GLOBALS["db_pref"] ."settings SET value='". $_POST["sitename"] ."' WHERE presence='". $_GET["pres"] ."' and name='sitename'");
		mysql_query("UPDATE ". $GLOBALS["db_pref"] ."settings SET value='". $_POST["copyright"] ."' WHERE presence='". $_GET["pres"] ."' and name='copyright'");
		if(!empty($_POST["navigation_home"])) {
			mysql_query("UPDATE ". $GLOBALS["db_pref"] ."settings SET value='". $_POST["navigation_home"] ."' WHERE presence='". $_GET["pres"] ."' and name='navigation_home'");
		}
		if(!empty($_POST["404error"])) {
			mysql_query("UPDATE ". $GLOBALS["db_pref"] ."settings SET value='". $_POST["404error"] ."' WHERE presence='". $_GET["pres"] ."' and name='404error'");
		}
		if(!empty($_POST["401error"])) {
			mysql_query("UPDATE ". $GLOBALS["db_pref"] ."settings SET value='". $_POST["401error"] ."' WHERE presence='". $_GET["pres"] ."' and name='401error'");
		}
		/*
		if(!empty($_POST["loginpage"])) {
			mysql_query("UPDATE ". $GLOBALS["db_pref"] ."settings SET value='". $_POST["loginpage"] ."' WHERE presence='". $_GET["pres"] ."' and name='loginpage'");
		} */
		if(!empty($_POST["production_url"])) {
			mysql_query("UPDATE ". $GLOBALS["db_pref"] ."settings SET value='". $_POST["production_url"] ."' WHERE presence='". $_GET["pres"] ."' and name='production_url'");
		}
		if(!empty($_POST["templatedir"])) {
			mysql_query("UPDATE ". $GLOBALS["db_pref"] ."settings SET value='". $_POST["templatedir"] ."' WHERE presence='". $_GET["pres"] ."' and name='templatedir'");
		}
		if(!empty($_POST["standard_language"])) {
			mysql_query("UPDATE ". $GLOBALS["db_pref"] ."settings SET value='". $_POST["standard_language"] ."' WHERE presence='". $_GET["pres"] ."' and name='standard_language'");
		}
	}
	
	$pres_settings=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."settings WHERE presence='". $_GET["pres"] ."'");
	$settings=array();
	for($i=0; $i<mysql_num_rows($pres_settings); $i++) {
		$row_pres_settings=mysql_fetch_object($pres_settings);
		$settings[$row_pres_settings->name]=$row_pres_settings->value;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title><?php echo getsetting("sitename"); ?> - Administration</title>
    <link media="screen" rel="stylesheet" href="css/style.css" type="text/css" />
    <script src="js/scripts.js" type="text/javascript"></script>
  </head>

  <body id="editgrey">
   	<div id="overview">
   	  <h1>Pr&auml;senzeinstellungen</h1>
   	  <img src="images/dir_symbol.gif" width="64" height="64" alt="" style="padding-right:20px;float:left;" />
   	  Konfigurieren Sie hier die Einstellungen f&uuml;r diese Pr&auml;senz.
   	  <br style="clear:both;" />
    </div>
    <div id="edit">
  	<p id="pageheadline2">Einstellungen</p>
  	<form action="<?php echo $_SERVER["PHP_SELF"]; ?>?pres=<?php echo $_GET["pres"]; ?>" method="post">
  		<table style="width:100%;padding:0px; margin:0px;border-top:0px;border-left:1px solid #aaaaaa;border-right:1px solid #aaaaaa;border-bottom:1px solid #aaaaaa; background-color:#ffffff" cellpadding="0" cellspacing="0">
  		  <tr onmouseover="setbgcolor(this, '#eeeeee')" onmouseout="setbgcolor(this, '#ffffff')">
  		    <td class="tdnormal">Titel der Pr&auml;senz:</td>
  		    <td class="tdnormal"><input type="text" name="sitename" style="width:300px;" value="<?php echo (isset($settings["sitename"]))?$settings["sitename"]:""; ?>" /></td>
  		  </tr>
  		  <tr onmouseover="setbgcolor(this, '#eeeeee')" onmouseout="setbgcolor(this, '#ffffff')">
  		    <td class="tdnormal">Copyright:</td>
  		    <td class="tdnormal"><input type="text" name="copyright" style="width:300px;" value="<?php echo (isset($settings["copyright"]))?$settings["copyright"]:""; ?>" /></td>
  		  </tr>
  		  <tr onmouseover="setbgcolor(this, '#eeeeee')" onmouseout="setbgcolor(this, '#ffffff')">
  		    <td class="tdnormal">Startnavigation:</td>
  		    <td class="tdnormal">
  		    	<select size="1" name="navigation_home" style="width:300px;">
  		    		<?php
  		    		$active=0;
  		    		if(isset($settings["navigation_home"])) {
  		    			$active=$settings["navigation_home"];
  		    		}
  		    		echo get_navigations($_GET["pres"],0,0,$active);
  		    		?>
  		    	</select>
  		    </td>
  		  </tr>
  		  <tr onmouseover="setbgcolor(this, '#eeeeee')" onmouseout="setbgcolor(this, '#ffffff')">
  		    <td class="tdnormal">Fehlerseite:</td>
  		    <td class="tdnormal">
  		    	<select size="10" name="404error" style="width:300px;">
  		    		<?php
  		    		$active=0;
  		    		if(isset($settings["404error"])) {
  		    			$active=$settings["404error"];
  		    		}
  		    		echo get_documents($_GET["pres"],0,0,$active);
  		    		?>
  		    	</select>
  		    </td>
  		  </tr>
  		  <tr onmouseover="setbgcolor(this, '#eeeeee')" onmouseout="setbgcolor(this, '#ffffff')">
  		    <td class="tdnormal">Zugriffsfehlerseite:</td>
  		    <td class="tdnormal">
  		    	<select size="10" name="401error" style="width:300px;">
  		    		<?php
  		    		$active=0;
  		    		if(isset($settings["401error"])) {
  		    			$active=$settings["401error"];
  		    		}
  		    		echo get_documents($_GET["pres"],0,0,$active);
  		    		?>
  		    	</select>
  		    </td>
  		  </tr>
  		  <!--
  		  <tr>
  		    <td>Loginseite:</td>
  		    <td>
  		    	<select size="10" name="loginpage" style="width:300px;">
  		    		<?php
  		    		$active=0;
  		    		if(isset($settings["loginpage"])) {
  		    			$active=$settings["loginpage"];
  		    		}
  		    		echo get_documents($_GET["pres"],0,0,$active);
  		    		?>
  		    	</select>
  		    </td>
  		  </tr> -->
  		  <tr onmouseover="setbgcolor(this, '#eeeeee')" onmouseout="setbgcolor(this, '#ffffff')">
  		    <td class="tdnormal">Hauptdomain:</td>
  		    <td class="tdnormal">
  		    	<select size="1" name="production_url" style="width:300px;">
  		    		<?php
  		    		$active=0;
  		    		$domains=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."domains WHERE presence='". $_GET["pres"] ."'");
  		    		if(isset($settings["production_url"])) {
		    			$active=$settings["production_url"];
		    		}
  		    		for($i=0; $i<mysql_num_rows($domains); $i++) {
  		    			$row_domain=mysql_fetch_object($domains);
  		    			echo "<option value=\"http://". $row_domain->domainname ."\"";
  		    			if ("http://". $row_domain->domainname==$active) {
  		    				echo " selected=\"selected\"";
  		    			}
  		    			echo ">". $row_domain->domainname;
  			    		echo "</option>";
  		    		}
  		    		?>
  		    	</select>
  		    </td>
  		  </tr>
  		  <tr onmouseover="setbgcolor(this, '#eeeeee')" onmouseout="setbgcolor(this, '#ffffff')">
  		    <td class="tdnormal">Templates:</td>
  		    <td class="tdnormal">
  		    	<select size="1" name="templatedir" style="width:300px;">
  		    		<?php
  		    		$active=0;
  		    		if(isset($settings["templatedir"])) {
		    			$active=$settings["templatedir"];
		    		}
	    			echo "<option value=\"templates/standard\"";
	    			if ($active=="templates/standard") {
	    				echo " selected=\"selected\"";
	    			}
	    			echo ">Standard</option>";
	    			echo "<option value=\"templates/". $_GET["pres"] ."\"";
	    			if ($active=="templates/". $_GET["pres"]) {
	    				echo " selected=\"selected\"";
	    			}
	    			echo ">Individuell</option>";
 		    		?>
  		    	</select>
  		    </td>
  		  </tr>
  		  <tr onmouseover="setbgcolor(this, '#eeeeee')" onmouseout="setbgcolor(this, '#ffffff')">
  		    <td class="tdnormal">Standard-Sprache:</td>
  		    <td class="tdnormal">
  		    	<select size="1" name="standard_language" style="width:300px;">
  		    		<?php
  		    		$active=0;
  		    		$languages=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."languages");
  		    		if(isset($settings["standard_language"])) {
		    			$active=$settings["standard_language"];
		    		}
		    		echo mysql_num_rows($languages);
  		    		for($i=0; $i<mysql_num_rows($languages); $i++) {
  		    			$row_language=mysql_fetch_object($languages);
  		    			echo "<option value=\"". $row_language->shortname ."\"";
  		    			if ($row_language->shortname==$active) {
  		    				echo " selected=\"selected\"";
  		    			}
  		    			echo ">". $row_language->name;
  			    		echo "</option>";
  		    		}
 		    		?>
  		    	</select>
  		    </td>
  		  </tr>
  		</table>
  		<input type="submit" value="Speichern" />
  	  </form>
  	</div>
  </body>
</html>
<?php
}
function get_navigations($presence, $startid=0, $level=0, $active=0) {
	$snav="";
	$navs=mysql_query("SELECT name, id FROM ". $GLOBALS["db_pref"] ."navigation WHERE subof='". $startid ."' and deleted='0' and presence='". $presence ."'");
	for($i=0; $i<mysql_num_rows($navs); $i++) {
		$navrow=mysql_fetch_object($navs);
		$space="";
		for($j=0; $j<$level; $j++) {
			$space.="&nbsp;&nbsp;";
		}
		$select="";
		if($active==$navrow->id) {
			$select=" selected=\"selected\"";
		}
		$snav.="<option". $select ." value=\"". $navrow->id ."\">". $space . $navrow->name ."</option>\n";
		$snav.=get_navigations($presence, $navrow->id, ($level + 1), $active);
	}
	return $snav;
}

function get_documents($presence, $startid=0, $level=0, $active=0) {
	$snav="";
	$navs=mysql_query("SELECT name, id FROM ". $GLOBALS["db_pref"] ."content_dirs WHERE subof='". $startid ."' and deleted='0' and presence='". $presence ."'");
	for($i=0; $i<mysql_num_rows($navs); $i++) {
		$navrow=mysql_fetch_object($navs);
		$space="";
		for($j=0; $j<$level; $j++) {
			$space.="&nbsp;&nbsp;";
		}
		$snav.="<optgroup label=\"". $space . $navrow->name ."\">\n";
		$dirdocs=mysql_query("SELECT id, pagetitle, id2 FROM ". $GLOBALS["db_pref"] ."content_documents WHERE ofdir='". $navrow->id ."' and deleted='0' and checkin_by>0");
		for($j=0; $j<mysql_num_rows($dirdocs); $j++) {
			$docrow=mysql_fetch_object($dirdocs);
			$select="";
			if($active==$docrow->id) {
				$select=" selected=\"selected\"";
			}
			$snav.="<option". $select ." value=\"". $docrow->id ."\">". $space . $docrow->pagetitle ."</option>\n";
		}
		$snav.=get_documents($presence, $navrow->id, ($level + 1), $active);
		$snav.="</optgroup>";
	}
	return $snav;
}
?>